package jobs.Factory;

import java.util.Scanner;

// 图形接口
interface Shape {
    void draw();
}

// 圆形实现
class Circle implements Shape {
    @Override
    public void draw() {
        System.out.println("绘制圆形");
    }
}

// 矩形实现
class Rectangle implements Shape {
    @Override
    public void draw() {
        System.out.println("绘制矩形");
    }
}

// 三角形实现
class Triangle implements Shape {
    @Override
    public void draw() {
        System.out.println("绘制三角形");
    }
}

// 图形工厂
class ShapeFactory {
    public static Shape createShape(String type) {
        if (type == null) return null;
        switch (type.toLowerCase()) {
            case "circle":
                return new Circle();
            case "rectangle":
                return new Rectangle();
            case "triangle":
                return new Triangle();
            default:
                throw new IllegalArgumentException("未知图形类型: " + type);
        }
    }
}

// 测试类
public class ShapeFactoryTest {
    public static void main(String[] args) {
        try (Scanner scanner = new Scanner(System.in)) {
            System.out.print("请输入要绘制的图形(circle/rectangle/triangle): ");
            String input = scanner.nextLine();
            try {
                Shape shape = ShapeFactory.createShape(input);
                shape.draw();
            } catch (Exception e) {
                System.out.println(e.getMessage());
            }
        }
    }
}
